package com.hilihili.controller.personalHomepageComponent;

import com.hilihili.domain.dto.FavoritesVideoDTO;
import com.hilihili.domain.dto.FavoritesVideoListDTO;
import com.hilihili.domain.entity.FavoritesVideoList;
import com.hilihili.service.IFavoritesVideoListService;
import com.hilihili.util.DateChangeUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @Author xhc
 * @Date 2024/1/26 11:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/hilihili/favoritesVideoList")
public class FavoritesVideoListController {
    @Autowired
    private IFavoritesVideoListService favoritesVideoListService;

    /**
     * 个人主页中，查看各个收藏夹里的视频列表
     * @param
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(FavoritesVideoList favoritesVideoList){
        if (favoritesVideoList.getFavoritesId() == null) return AjaxResult.error("查询出错");
        Map<String,Object> map = new HashMap<>();
        // 查询total
        int total = favoritesVideoListService.selectCount(favoritesVideoList.getFavoritesId());
        map.put("total",total);
        favoritesVideoList.setStartIndex((favoritesVideoList.getStartIndex() - 1)* favoritesVideoList.getMaxCount());
        List<FavoritesVideoDTO> favoritesVideoDTOS = favoritesVideoListService.selectList(favoritesVideoList);
        favoritesVideoDTOS.forEach(item -> {
            // 格式化时间
            item.setCollectTime(DateChangeUtil.formatDateGetYear(item.getCreateTime()));
            item.setContributeTime(DateChangeUtil.formatDateGetYear(item.getVideoCreateTime()));
        });
        map.put("favoritesVideoList",favoritesVideoDTOS);
        return AjaxResult.success(map);
    }

    /**
     * 视频页收藏功能
     * @param favoritesVideoListDTO
     * @return
     */
    @GetMapping("/addFavoritesVideoList")
    public AjaxResult addFavoritesVideoList(FavoritesVideoListDTO favoritesVideoListDTO){

        favoritesVideoListService.addFavoritesVideoList(favoritesVideoListDTO);
        return AjaxResult.success("操作成功");
    }



    public void insert(){
        FavoritesVideoList favoritesVideoList = new FavoritesVideoList();
        for (int i = 106; i < 200; i++) {
            favoritesVideoList.setFavoritesId(1L);
            favoritesVideoList.setVideoId(Long.parseLong(i+""));
            favoritesVideoList.setCreateTime(new Date());
            favoritesVideoListService.insertList(favoritesVideoList);
        }
    }

}
